<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : sql-result-style.xsl
    Created on : January 6, 2011, 10:27 AM
    Author     : ReutyCheng
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <!-- TODO customize transformation rules
         syntax recommendation http://www.w3.org/TR/xslt
    -->
  <xsl:template match="/">
    <html>
      <head>
        <title>SQL Results</title>
        <style type="text/css">
          html, body, p, table, td, h1, h2, h3, h4, h5, h6
          {
          padding: 0;
          margin: 0;
          border: none;
          font-family: Arial Unicode MS, Arial, sans-serif;
          font-size: 12pt;
          }
          body
          {
          padding: 5px;
          }
          table
          {
          border: none;
          border-spacing: 0;
          border-collapse: collapse;
          width: 100%;
          }
          tr
          {
          background: #FFFFFF;
          }
          th, td
          {
          padding: 0px 3px;
          line-height: 25px;
          }
          .results
          {
          background: #DBE9E8;
          border: solid 1px #B8C0BF;
          margin-bottom: 20px;
          padding: 5px;
          }
          .title
          {
          border-bottom: 1px solid #959595;
          padding-bottom: 10px;
          margin-bottom: 10px;
          }
          .sql
          {
          color: #FF0000;
          }
          .result
          {
          border: 1px solid #000000;
          }
          .result_header
          {
          background: #000000;
          color: #FFFFFF;
          }
          .empty
          {
          font-style: italic;
          font-weight: bold;
          text-align: center;
          color: #F3B3B3;
          }
          .index
          {
          width: 50px;
          text-align: center;
          font-weight: bold;
          background: #EEB5B5;
          }
          .even
          {
          background: #EEEEEE;
          }
          .odd
          {
          }
          .copyright
          {
          color: #FF0000;
          font-style: italic;
          font-size: 10pt;
          margin: 10px 0px;
          text-align: right;
          }
          .dom_header
          {
          border-bottom: solid 1px #FF0000;
          }
          .dom_bottom
          {
          border-top: solid 1px #FF0000;
          }
        </style>
      </head>
      <body>
        <div class="copyright dom_header">By CES</div>
        <xsl:for-each select="SQLResults/SQLResult">
          <div class="results">
            <div class="title">
              <h3 style="font-size: 15pt;">SQL: <span class="sql"><xsl:value-of select="@sql" /></span></h3>
              <h3 style="font-size: 15pt;">PARAMS: <span class="sql"><xsl:value-of select="@params" /></span></h3>
              <p>File Create Time: <span><xsl:value-of select="@createdTime" /></span></p>
            </div>
            <h3 style="font-size: 15pt;">Result Meta:</h3>
            <table class="result">
              <thead>
                  <tr class="result_header">
                      <th>Meta Name</th>
                      <th>Meta Value</th>
                  </tr>
              </thead>
              <tbody>
                <xsl:choose>
                  <xsl:when test="count(Metas/Meta) = 0">
                    <tr class="odd">
                      <td class="empty" colspan="2">Empty</td>
                    </tr>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:for-each select="Metas/Meta">
                      <tr class="odd">
                        <td style="background: #E0E0E0; text-align: center;"><xsl:value-of select="@metaname" /></td>
                        <td><xsl:value-of select="@metavalue" /></td>
                      </tr>
                    </xsl:for-each>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:for-each select="Metas">
                  <xsl:for-each select="Row">
                    <xsl:choose>
                      <xsl:when test="position() mod 2 = 0">
                        <tr class="even">
                          <td class="index"><xsl:value-of select="position()" /></td>
                          <xsl:for-each select="Object">
                            <td><xsl:value-of select="." /></td>
                          </xsl:for-each>
                        </tr>
                      </xsl:when>
                      <xsl:otherwise>
                        <tr class="odd">
                          <td class="index"><xsl:value-of select="position()" /></td>
                          <xsl:for-each select="Object">
                            <td><xsl:value-of select="." /></td>
                          </xsl:for-each>
                        </tr>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:for-each>
                </xsl:for-each>
              </tbody>
            </table>
            <h3 style="font-size: 15pt;">Result:</h3>
            <table class="result">
              <thead>
                <xsl:for-each select="Columns">
                  <tr class="result_header">
                    <th>Index</th>
                    <xsl:for-each select="Column">
                      <th><xsl:value-of select="." /></th>
                    </xsl:for-each>
                  </tr>
                </xsl:for-each>
              </thead>
              <tbody>
                <xsl:for-each select="Rows">
                  <xsl:for-each select="Row">
                    <xsl:choose>
                      <xsl:when test="position() mod 2 = 0">
                        <tr class="even">
                          <td class="index"><xsl:value-of select="position()" /></td>
                          <xsl:for-each select="Object">
                            <td><xsl:value-of select="." /></td>
                          </xsl:for-each>
                        </tr>
                      </xsl:when>
                      <xsl:otherwise>
                        <tr class="odd">
                          <td class="index"><xsl:value-of select="position()" /></td>
                          <xsl:for-each select="Object">
                            <td><xsl:value-of select="." /></td>
                          </xsl:for-each>
                        </tr>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:for-each>
                </xsl:for-each>
              </tbody>
            </table>
          </div>
        </xsl:for-each>
        <div class="copyright dom_bottom">By CES</div>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>
